<template>
  <demoBlock title="基础用法" padding>
    <vcu-table :columns="columns" :datas="data">
      <template #customTitle="{ record }">
        <vcu-icon name="profile" /> {{ record.title }}
      </template>
      <template #name="{ text }">
        <span class="blue-text">{{ text }}</span>
      </template>
      <template #action="{ record }">
        <vcu-button size="mini" icon="add" @click="handleAdd(record)">
          添加
        </vcu-button>
      </template>
    </vcu-table>
  </demoBlock>
</template>

<script>
import { defineComponent, ref } from "vue";
const columns = [
  {
    title: "姓名",
    dataIndex: "name",
    key: "name",
    slots: { title: "customTitle", customRender: "name" },
  },
  {
    title: "年龄",
    dataIndex: "age",
    key: "age",
  },
  {
    title: "地址",
    dataIndex: "address",
    key: "address",
  },
  {
    title: "标签",
    key: "tags",
    dataIndex: "tags",
  },
  {
    title: "操作",
    key: "action",
    slots: { customRender: "action" },
  },
];

const data = [
  {
    key: "1",
    name: "张三",
    age: 32,
    address: "火星",
    tags: "漂亮的",
  },
  {
    key: "2",
    name: "李四",
    age: 42,
    address: "地球",
    tags: "失败者",
  },
  {
    key: "3",
    name: "王五",
    age: 32,
    address: "月亮",
    tags: "冰冷的",
  },
];
export default defineComponent({
  setup() {
    const handleAdd = (record) => {
      console.info(record);
    };
    return {
      data,
      columns,
      handleAdd,
    };
  },
});
</script>
